import vue from "@vitejs/plugin-vue";
import { viteMockServe } from "vite-plugin-mock";
import { resolve } from "path";
import { svgBuilder } from "./build/svg/svgBuilder.ts";
import vueJsx from "@vitejs/plugin-vue-jsx";

// https://vitejs.dev/config/
export default ({ command }) => {
  let prodMock = false;
  return {
    // export default defineConfig({
    server: {
      proxy: {
        "/dev-api": {
          target: "http://localhost:3000",
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/dev-api/, ""),
        },
        "/server-proxy": {
          // target: 'http://192.168.2.13:3001/',
          target: "http://10.36.197.118:10001/server-proxy",
          // target: "https://bcdsg.wenzhou.gov.cn:10002/server-proxy",
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/server-proxy/, ""),
        },
      },
    },
    plugins: [
      vue(),
      vueJsx(),
      svgBuilder("./src/icons/svg/"),
      viteMockServe({
        supportTs: false,
        // default
        mockPath: "mock",
        localEnabled: command === "serve",
        prodEnabled: command !== "serve" && prodMock,
        injectCode: `
            import { setupProdMockServer } from '/build/mock/mockProdServer.js';
            setupProdMockServer();
          `,
      })
    ],
    build: {
      minify: "terser",
      terserOptions: {
        compress: {
          //生产环境时移除console
          drop_console: true,
          drop_debugger: true,
        },
      },
    },
    resolve: {
      alias: {
        "@": resolve(__dirname, "./src"),
      },
    },
  };
};
// )
